package com.oj.ojbackendjudgeservice.judge;

import com.oj.ojbackendjudgeservice.judge.strategy.DefaultJudgeStrategy;
import com.oj.ojbackendjudgeservice.judge.strategy.JavaLanguageJudgeStrategy;
import com.oj.ojbackendjudgeservice.judge.strategy.JudgeContext;
import com.oj.ojbackendjudgeservice.judge.strategy.JudgeStrategy;
import ojbackendmodel.model.codesandbox.JudgeInfo;
import ojbackendmodel.model.entity.QuestionSubmit;
import org.springframework.stereotype.Service;

@Service
public class JudgeManager {
    /**
     * 执行判题，使用了策略模式，不同的编程语言执行不同的判断策略
     * @param judgeContext
     * @return
     */
    JudgeInfo doJudge(JudgeContext judgeContext) {
        QuestionSubmit questionSubmit = judgeContext.getQuestionSubmit();
        String language = questionSubmit.getLanguage();
        JudgeStrategy judgeStrategy = new DefaultJudgeStrategy();
        if ("java".equals(language)) {
            judgeStrategy = new JavaLanguageJudgeStrategy();
        }
        return judgeStrategy.doJudge(judgeContext);
    }

}
